﻿using DimensionsHelper.Common.Contracts.Metadata;

namespace DimensionsHelper.Services.Metadata;

public abstract class MetadataNamedObject(IMetadataDocument document, ObjectType type, string name)
    : MetadataObject(document, type), IMetadataNamedObject
{
    private string? _fullName;

    public string Name { get; protected internal set; } = name;

    public string FullName
    {
        get => GetFullName();

        set => SetFullName(value);
    }

    public static string GetFullName(IMetadataNamedObject obj)
    {
        var full = obj.Name;
        var parent = obj.Parent;

        while (parent is MetadataNamedObject namedObject)
        {
            full = namedObject.Name + "." + full;
            parent = parent.Parent;
        }

        return full;
    }


    protected virtual string GetFullName()
    {
        return _fullName ?? GetFullName(this);
    }

    protected virtual void SetFullName(string value)
    {
        _fullName = value;
    }
}